package com.flash.InventoryManagement.service.impl;

import com.flash.InventoryManagement.entity.CashStock;
import com.flash.InventoryManagement.entity.SecurityStock;
import com.flash.InventoryManagement.mapper.CashStockMapper;
import com.flash.InventoryManagement.service.CashStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jr
 * @version 1.0
 * @date 2022/8/22
 */
@Service
public class CashStockServiceImpl implements CashStockService {

    @Autowired
    CashStockMapper cashStockMapper;

    @Override
    public int countCashStock() {
        return cashStockMapper.countCashStock();
    }

    @Override
    public List<CashStock> selectCashStock(CashStock cashStock,int page, int limit) {
        HashMap map = new HashMap();
        map.put("strWhere", buildWhere(cashStock));
        map.put("page",(page-1)*limit+1);
        map.put("limit",limit*page);
        return cashStockMapper.selectCashStock(map);
    }

    @Override
    public int insertCashStock(CashStock cashStock) {
        return cashStockMapper.insertCashStock(cashStock);
    }

    @Override
    public int deleteCashStock(CashStock cashStock) {
        return cashStockMapper.deleteCashStock(cashStock);
    }

    @Override
    public int updateCashStock(CashStock cashStock) {
        return cashStockMapper.updateCashStock(cashStock);
    }


    public String buildWhere (CashStock cashStock) {
        StringBuffer strWhere = new StringBuffer();
        if (cashStock.getCashStockId()!=null && !cashStock.getCashStockId().equals("")){
            strWhere.append(" and c.cashStockId like '%" + cashStock.getCashStockId() +"%'" );
        }
        if (cashStock.getDateCashStock()!=null && !cashStock.getDateCashStock().equals("")){
            strWhere.append(" and c.dateCashStock like '%" + cashStock.getDateCashStock() +"%'" );
        }
        return strWhere.toString();
    }



}
